package com.ruoyi.backend.controller.orderManagement;

import com.ruoyi.backend.domain.orderManagement.Order;
import com.ruoyi.backend.service.orderManagement.ICarWashOrderService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 洗车订单Controller
 *
 * @author 王冰冰
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/carWashOrder")
public class CarWashOrderController extends BaseController {

    private final ICarWashOrderService iCarWashOrderService;

    public CarWashOrderController(ICarWashOrderService iCarWashOrderService) {
        this.iCarWashOrderService = iCarWashOrderService;
    }

    /**
     * 查询洗车订单列表
     */
    @RequiresPermissions("orderManagement:carWashOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(Order order) {
        startPage();
        List<Order> list = iCarWashOrderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * 导出洗车订单列表
     */
    @RequiresPermissions("orderManagement:carWashOrder:export")
    @Log(title = "洗车订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Order order) {
        List<Order> list = iCarWashOrderService.selectOrderList(order);
        ExcelUtil<Order> util = new ExcelUtil<>(Order.class);
        util.exportExcel(response, list, "洗车订单数据");
    }

    /**
     * 获取洗车订单详细信息
     */
    @RequiresPermissions("orderManagement:carWashOrder:query")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return success(iCarWashOrderService.selectOrderByOrderId(orderId));
    }

    /**
     * 新增洗车订单
     */
    @RequiresPermissions("orderManagement:carWashOrder:add")
    @Log(title = "洗车订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Order order) {
        return toAjax(iCarWashOrderService.insertOrder(order));
    }

    /**
     * 修改洗车订单
     */
    @RequiresPermissions("orderManagement:carWashOrder:edit")
    @Log(title = "洗车订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Order order) {
        return toAjax(iCarWashOrderService.updateOrder(order));
    }

    /**
     * 删除洗车订单
     */
    @RequiresPermissions("orderManagement:carWashOrder:remove")
    @Log(title = "洗车订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(iCarWashOrderService.deleteOrderByOrderIds(orderIds));
    }
}